package cn.edu.hubu.javaparkinglot.service.impl;

import cn.edu.hubu.javaparkinglot.VO.ResultVO;
import cn.edu.hubu.javaparkinglot.entity.Car;
import cn.edu.hubu.javaparkinglot.mapper.CarMapper;
import cn.edu.hubu.javaparkinglot.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**实现CarService接口**/
@Service
public class CarServicelmpl implements CarService {

    @Autowired
    private CarMapper carMapper;

    //查询carId是否存在
    @Override
    public ResultVO checkCarId(String carId){
        Car car = carMapper.selectByCarId(carId);
        if (car!=null){
            return new ResultVO(200,"查询成功！",car);
        }
        else{
            return new ResultVO(500,"该车辆无进出数据",car);
        }
    }

    //查询seatId是否存在车辆停放
    @Override
    public ResultVO checkSeatId(int seatId){
        Car car = carMapper.selectBySeatId(seatId);
        if (car!=null){
            return new ResultVO(200,"查询成功！",car);
        }
        else{
            return new ResultVO(500,"该车位处于空闲状态",car);
        }
    }

    @Override
    public ResultVO checkTime(String startTime, String endTime) {
        List<Car> cars = carMapper.selectByTime(startTime, endTime);
        if (cars!= null &&!cars.isEmpty()) {
            return new ResultVO(200, "查询成功！", cars);
        } else {
            return new ResultVO(500, "该时间段没有车辆进入", null);
        }
    }
}
